<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>文章列表-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
		<meta name="Description" content="基于layUI数据表格操作"/>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../static/css/font.css">
		<link rel="stylesheet" href="../../static/css/weadmin.css">
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
	      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	    <![endif]-->
		<style type="text/css">
			.layui-form-switch {
				width: 55px;
			}			
			.layui-form-switch em {
				width: 40px;
			}			
			.layui-form-onswitch i {
				left: 45px;
			}
			body{overflow-y: scroll;}
		</style>
	</head>

	<body>
		<div class="weadmin-nav">
			<span class="layui-breadcrumb">
        <a href="">首页</a>
        <a>
          <cite>菜系管理</cite></a>
      </span>
			<a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
				<i class="layui-icon" style="line-height:30px">&#x1002;</i></a>
		</div>
		<div class="weadmin-body">
			<div class="layui-row">
			<div class="weadmin-block demoTable">
				<button class="layui-btn" onclick="WeAdminShow('添加菜系','./add.html',600,400)"><i class="layui-icon">&#xe61f;</i>添加</button>
			</div>
				<table class="layui-table" >
					<thead>
					<tr>
						<th>
							<div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
						</th>
						<th>菜系编号</th>
						<th>菜系名称</th>
						<th>操作</th>
					</tr>
					</thead>
					<tbody id="cuisineList">
					<tr data-id="1">
						<td>
							<div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="1"><i class="layui-icon">&#xe605;</i></div>
						</td>
						<td>1</td>
						<td>纽约</td>
						<td class="td-manage">
							<input type="button" value="预定" name="status">
							<a title="删除" onclick="member_del(this,'要删除的id')" href="javascript:;">
								<i class="layui-icon">&#xe640;</i>
							</a>
						</td>
					</tr>
					</tbody>
				</table>
		</div>
		</div>
	</body>
	<script src="../../static/js/jquery.js"></script>
	<script src="../../static/js/setAjax.js"></script>
	<script src="../../lib/layui/layui.js" charset="utf-8"></script>
	<script src="../../static/js/eleDel.js" type="text/javascript" charset="utf-8"></script>
<script>
	layui.use(['form', 'layer'], function() {
		var layer = layui.layer;
		$.ajax({
			url:'/cuisine',
			type:'get',
			dataType:'json',
			success:function (data) {
				layer.msg(data.message,{icon:1,time:2000});
				if(data.state=="success"){
					var _html = '';
					for (var i = 1;i<=data.cuisineList.length;i++) {
						_html+=`<tr data-id=${i}>
<td>
<div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id=${i}>
<i class="layui-icon">&#xe605;</i>
</div></td><td>${i}</td>
<td>${data.cuisineList[i-1].cuisineName}</td>
<td class="td-manage">
<input class="layui-btn" onclick="WeAdminEdit('菜系编辑','./edit.html',${data.cuisineList[i-1].cuisineId},600,400)" type="button" value="更新">
<input type="button" onclick="deleteCuisine(${data.cuisineList[i-1].cuisineId})" class="layui-btn layui-btn-danger" value="删除">
</td></tr>`;
					}
					$("#cuisineList").html(_html);
				}else {
					layer.msg(data.message,{icon:2,time:2000})
				}
			},
			error:function () {
				console.log("出错了")
			}
		});
	});
	function deleteCuisine(id) {
		layui.use(['layer'], function() {
			var layer = layui.layer;
			layer.confirm('确认要删除吗？删除菜系会删除所有熟悉菜系的菜品！', function(index) {
				//发异步删除数据
				$.ajax({
					url:'/cuisine',
					type:'post',
					dataType:'json',
					data:{
						_method:'delete',
						'cuisineId':id
					},
					success:function (data) {
						if (data.state=="success"){
							layer.msg(data.message,{icon:1,time:2000},function () {
								location.reload();
							})
						}else {
							layer.msg(data.message,{icon:2,time:2000})
						}
					}
				})
			});
		});
	}
</script>
</html>